﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using wsn.ap;
using wsn.model;

namespace wsn.atos
{
    class SensorSerialize  //规范化传感器数据
    {
        public AccessPointData execute(int[] t)
        {
            AccessPointData Q=new AccessPointData();
            Sensor_Data(t, Q);
            Sensor_Type(t, Q);
            Sensor_ID(t, Q);
            Sensor_Hopcount(t, Q);
            return Q;
        }

        public bool Sensor_Type(int[] t, AccessPointData Q)//为true表示成功分配类型，反之表示分配失败，应该丢去该段数据
        {
            //string[] Check = { " ", "TH", "T", "LIGHT", "FLUX", "BLOOD_PRESSURE", "ALTITUDE", "HOARE", "RAIN" };
            //if (t[0] * 16 + t[1] >= Check.Length || t[0] * 16 + t[1] <= 0) return false;
            Q.Sensor_Type =t[0] * 16 + t[1];
            return true;
        }
        public bool Sensor_ID(int[] t, AccessPointData Q) //ID
        {
            if (t[4] * 16 + t[5] < 0) return false;
            Q.Sensor_ID = t[4] * 16 + t[5];
            return true;
        }
        public bool Sensor_Hopcount(int[] t, AccessPointData Q)
        {
            if (t[8] < 0) return false;
            Q.Sensor_Hopcout = t[8];
            return true;
        }

        public bool Sensor_Data(int[] t, AccessPointData Q)
        {
            int q;
            q = t[9];
            for (int k = 10; k < t.Length - 1; k++)
            {
                q = q * 16 + t[k];
            }
            Q.Sensor_Data1 = q;
            return true;
        }


    }
}
